﻿/**
 * Peter
 * Created by: Peter Development Team
 *    http://peter.codeplex.com/
 * 
 * GNU General Public License version 2 (GPLv2)
 *    http://peter.codeplex.com/license
 **/

using System.Xml.Serialization;
using Peter.Common;

namespace Peter.Ftp.Data
{
   /// <summary>
   /// Represents an ftp session.
   /// </summary>
   public class FtpConnectionData : ViewModelBase
   {
      private string m_Name;
      private string m_UserName;
      private string m_Server;
      private string m_Password;
      private int m_TimeOut = 10;
      private int m_Port = 21;
      private string m_WorkingPath = "/";
      private bool m_AskForPassword;
      private string m_SecurePassword;

      /// <summary>
      /// Gets or Sets the connection's name.
      /// </summary>
      public string Name
      {
         get { return this.m_Name; }
         set
         {
            this.m_Name = value;
            this.RaisePropertyChanged ("Name");
         }
      }

      /// <summary>
      /// Gets or Sets the user name.
      /// </summary>
      public string UserName
      {
         get { return this.m_UserName; }
         set
         {
            this.m_UserName = value;
            this.RaisePropertyChanged ("UserName");
         }
      }

      /// <summary>
      /// Gets or Sets the server.
      /// </summary>
      public string Server
      {
         get { return this.m_Server; }
         set
         {
            this.m_Server = value;
            this.RaisePropertyChanged ("Server");
         }
      }

      /// <summary>
      /// Gets or Sets the user's password.
      /// </summary>
      [XmlIgnore]
      public string Password
      {
         get { return this.m_Password; }
         set
         {
            if (this.m_Password != value)
            {
               this.m_Password = value;
               this.RaisePropertyChanged ("Password");
               if (!string.IsNullOrEmpty (this.m_Password))
                  this.SecurePassword = Crypto.EncryptStringAes (this.m_Password, "IFOODOAKANFRJDKV");
               else
                  this.SecurePassword = string.Empty;
            }
         }
      }

      /// <summary>
      /// Gets or Sets the secured password.
      /// </summary>
      public string SecurePassword
      {
         get { return this.m_SecurePassword; }
         set
         {
            if (this.m_SecurePassword != value)
            {
               this.m_SecurePassword = value;
               this.RaisePropertyChanged ("SecurePassword");
               if (!string.IsNullOrEmpty (this.m_SecurePassword))
                  this.Password = Crypto.DecryptStringAes (this.m_SecurePassword, "IFOODOAKANFRJDKV");
               else
                  this.Password = string.Empty;
            }
         }
      }

      /// <summary>
      /// Gets or Sets the system should ask for a password.
      /// </summary>
      public bool AskForPassword
      {
         get { return this.m_AskForPassword; }
         set
         {
            if (this.m_AskForPassword != value)
            {
               this.m_AskForPassword = value;
               this.RaisePropertyChanged ("AskForPassword");
               if (this.m_AskForPassword)
               {
                  this.Password = "";
               }
            }
         }
      }

      /// <summary>
      /// Gets or Sets the ftp port.
      /// </summary>
      public int Port
      {
         get { return this.m_Port; }
         set
         {
            this.m_Port = value;
            this.RaisePropertyChanged ("Port");
         }
      }

      /// <summary>
      /// The working directory
      /// </summary>
      public string WorkingPath
      {
         get { return m_WorkingPath; }
         set
         {
            m_WorkingPath = value;
            this.RaisePropertyChanged ("WorkingPath");
         }
      }

      /// <summary>
      /// Timeout waiting for a response from server, in seconds.
      /// </summary>
      public int Timeout
      {
         get { return m_TimeOut; }
         set
         {
            m_TimeOut = value;
            this.RaisePropertyChanged ("Timeout");
         }
      }
   }
}
